from rest_framework import serializers

from headline.models import Article
from question.models import Label, Question, Reply
from recruit.models import Enterprise, Recruit
from users.models import User


# 收藏文章
class UserArticleSerializer(serializers.ModelSerializer):
    user_id = serializers.IntegerField()
    user = serializers.StringRelatedField()

    class Meta:
        model = Article
        fields = '__all__'


# 标签
class UserLabelSerializer(serializers.ModelSerializer):
    class Meta:
        model = Label
        fields = '__all__'


# 回答的问题
class AnswerQuestionSerializer(serializers.ModelSerializer):
    # problem_id = serializers.IntegerField()
    # problem = serializers.StringRelatedField()

    class Meta:
        model = Reply
        exclude = '__all__'


# 提问
class UserQuestionSerializer(serializers.ModelSerializer):
    class Meta:
        model = Question
        fields = "__all__"


# 职位
class EnterpiseRecruitSerializer(serializers.ModelSerializer):
    class Meta:
        model = Recruit
        fields = '__all__'


# 企业
class UserEnterpiseSerializer(serializers.ModelSerializer):
    recruits = serializers.StringRelatedField()

    class Meta:
        model = Enterprise
        fields = ('id', 'name', 'labels', 'logo', 'recruits', 'summary')


# 详情
class UserAdminSerializer(serializers.ModelSerializer):
    labels = UserLabelSerializer(many=True, read_only=True)

    questions = UserQuestionSerializer(many=True, read_only=True)
    collected_articles = UserArticleSerializer(many=True, read_only=True)
    enterpises = UserEnterpiseSerializer(many=True, read_only=True)
    # answer_question = AnswerQuestionSerializer(many=True)

    class Meta:
        model = User
        fields = "__all__"
        extra_kwargs = {
            'password': {
                'min_length': 8,
                'write_only': True

            },
        }

        # exclude = ('password', 'last_login', 'is_superuser', 'first_name', 'last_name', 'is_staff', 'is_active',
        #            'date_joined', 'nickname', 'update_date', 'groups', 'user_permissions', 'fans',)

    # def update(self, instance, validated_data):
    #
    #     super().update(instance, validated_data)
    #
    #     return instance
